package com.rlz.base.weiget

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.rlz.base.R
import com.rlz.drawable.helper.Shape
import kotlinx.android.synthetic.main.dialog_loading.*

/**
 * Created by RLZ
 * on 2021/3/16
 *
 */
class LoadingDialogFragment constructor(hintMsg: String?) : DialogFragment() {
    var mMessage: String = hintMsg!!

    var loadView: CNLoadingView? = null
    var mTitleView: TextView? = null

    override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.dialog_loading, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        isCancelable = false
        loadView = view.findViewById(R.id.loading_view)
        mTitleView = view.findViewById(R.id.loading_content_view)
        root.background = Shape.sp(R.color.color95000000, 10f)

        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setTitle();
    }

    private fun setTitle() {
        if (!TextUtils.isEmpty(mMessage))
            mTitleView?.text = mMessage
    }

    override fun dismiss() {
        super.dismiss()
        loadView?.stopAnimation()
    }

    override fun show(manager: FragmentManager, tag: String?) {
        super.show(manager, tag)
        loadView?.startAnimation()

    }
}